package com.iptv.grape.ui.adpt;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.iptv.grape.R;

import java.util.HashMap;
import java.util.List;

public class SystemAdpt extends BaseAdapter {
    private Context ctx;
    private List<HashMap<String,String>> lists;
    public SystemAdpt(Context ctx, List<HashMap<String,String>> lists){
        this.ctx = ctx;
        this.lists = lists;
    }
    @Override
    public int getCount() {
        return lists==null?0:lists.size();
    }

    @Override
    public Object getItem(int position) {
        position= position>lists.size()?lists.size()-1:position;
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        position =  position>lists.size()?lists.size()-1:position;
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null){
            holder= new Holder();
            convertView = View.inflate(ctx, R.layout.item_system, null);
            holder.tvKey = convertView.findViewById(R.id.tvKey);
            holder.tvValue = convertView.findViewById(R.id.tvValue);
            convertView.setTag(holder);
        }else
            holder= (Holder) convertView.getTag();
        position =  position>lists.size()?lists.size()-1:position;
        HashMap<String,String> data = lists.get(position);
        holder.tvKey.setText(data.get("key"));
        holder.tvValue.setText(data.get("value"));
        return convertView;
    }

    private class Holder{
        private TextView tvKey;
        private TextView tvValue;
    }
}
